//
//  MainTabBarController.swift
//  SinaWeiBo
//
//  Created by moon on 15/10/5.
//  Copyright © 2015年 moon. All rights reserved.
//

import UIKit

class MainTabBarController: UITabBarController {

    @IBOutlet weak var mainTabBar: MainTabBar!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //给跟控制器添加子控制器
        
        addChildViewControllers()
        
       // self.tabBar.tintColor=UIColor.orangeColor()
        
        mainTabBar.centerButton.addTarget(self, action: "centerButtonDidClicked", forControlEvents: UIControlEvents.TouchUpInside)
        
        
    }
 
   
    func centerButtonDidClicked(){
    
    print(__FUNCTION__)
    
    
    }
    
    
    
  private func addChildViewControllers(){
        
        
       //把sb名,标题名,和图片名称作为参数传给下面的函数
        
        addchildViewController("Home", title: "首页", imageName: "tabbar_home")
        
        addchildViewController("Message", title: "消息", imageName: "tabbar_message_center")
        
        addchildViewController("Discover", title: "发现", imageName: "tabbar_discover")
        
        addchildViewController("Profile", title: "我", imageName: "tabbar_profile")
        
        
    }
    
    
    //创建子控制器,设置自控器的标题及tabar图片
    
  private func addchildViewController(sbName:String,title: String,imageName:String) {
        
        let storyBoard = UIStoryboard(name: sbName, bundle: nil)
        
        let nav=storyBoard.instantiateInitialViewController() as! UINavigationController
        
        nav.topViewController?.title=title
        
        nav.tabBarItem.image=UIImage(named: imageName)
        
        
        addChildViewController(nav)
        
        
        
        
        
        
    }
    
    

}
